package mapEdit;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;

import dataTree.DataTree;
import readExcel.ReadExcelList;

import org.eclipse.swt.widgets.Button;


import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class DataMap extends Composite {
	private DataTree dt;
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public DataMap(Composite parent, int style) {
		super(parent, style);
		setLayout(new FormLayout());
		ReadExcelList rel=new ReadExcelList();

		Button button = new Button(this, SWT.NONE);
		
		button.setLayoutData(new FormData());
		FormData bt_dataDetail = new FormData();
		bt_dataDetail.bottom = new FormAttachment(0,40);
		bt_dataDetail.top = new FormAttachment(0,10);
		bt_dataDetail.right = new FormAttachment(100, -10);
		bt_dataDetail.left= new FormAttachment(100,-80);
		button.setText("\u5BFC\u5165");
		button.setLayoutData(bt_dataDetail);
		
		EditMap em = new EditMap(this, SWT.NONE);
		FormData fd_dataDetail = new FormData();
		fd_dataDetail.bottom = new FormAttachment(100,0);
		fd_dataDetail.top = new FormAttachment(0,35);
		fd_dataDetail.right = new FormAttachment(100, 0);
		fd_dataDetail.left= new FormAttachment(0);
		em.setLayoutData(fd_dataDetail);
		this.dt=em.getDtree();
		
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				FileDialog filedialog= new FileDialog(parent.getShell(),SWT.SAVE);
				String xx=filedialog.open();
				rel.setExcelPath(xx);
				//rel.readExcel();
				//em.setTreeDtree(rel.readExcel());
				//em.init();
				dt.getTreeViewer().setInput(rel.readExcel());
			}
		});
		
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
